﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
//using System.Xml.Linq;
using System.Data;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.BLL;
using Telerik.Web.UI;

namespace KPIS.GERP.GHRMS.APP.App_UI.UserControls
{
    public partial class RC_Catalogs : System.Web.UI.UserControl
    {
        private SsMng ssMng = new SsMng();
        private RecruitCatalogBLL catBLL = new RecruitCatalogBLL();
        private object _dataItem = null;

        protected void Page_Load(object sender, EventArgs e)
        {

        }
        public object DataItem
        {
            get
            {
                return this._dataItem;
            }
            set
            {
                this._dataItem = value;
            }
        }
        protected bool IsUserControlPostBack
        {
            get
            {
                return this.ViewState["IsUserControlPostBack"] != null;
            }
        }

        protected override void OnLoad(System.EventArgs e)
        {
            base.OnLoad(e);

            if (!IsUserControlPostBack)
            {
                this.ViewState.Add("IsUserControlPostBack", true);
            }
            if (DataItem != null)
            {
                ListYear();

                if (!(DataItem is Telerik.Web.UI.GridInsertionObject))
                {
                    lblSequence.Text = DataBinder.Eval(DataItem, "CAT_SEQ").ToString();
                    cmbYear.SelectedValue = DataBinder.Eval(DataItem, "BG_YEAR").ToString();
                    txtPeriod.Text = DataBinder.Eval(DataItem, "CAT_PERIOD").ToString();
                    txtName.Text = DataBinder.Eval(DataItem, "CAT_NAME").ToString();
                    txtRemarks.Text = DataBinder.Eval(DataItem, "REMARKS").ToString();

                    this.ViewState.Add("IsUserControlPostBack", true);
                }
                else
                {
                    cmbYear.SelectedValue = Session["BGYEAR"].ToString();                    
                }
            }
        }
        public void ListYear()
        {
            DataTable dt = new DataTable();
            DataColumn dc = dt.Columns.Add("Name");

            for (int i = 2500; i <= 2600; i++)
            {
                dt.Rows.Add(Convert.ToString(i));
            }
            cmbYear.DataSource = dt;
            cmbYear.DataBind();
        }
        protected void btnAddnew_Click(object sender, EventArgs e)
        {
            catBLL.Insert(Int32.Parse(cmbYear.SelectedValue)
                , txtPeriod.Text
                , txtName.Text
                , Int32.Parse(Session["EMPTYPE"].ToString())
                , txtRemarks.Text
                , ssMng.EmpSeqI);
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            catBLL.Update(Int32.Parse(lblSequence.Text)
                , Int32.Parse(cmbYear.SelectedValue)
                , txtPeriod.Text
                , txtName.Text
                , Int32.Parse(Session["EMPTYPE"].ToString())
                , txtRemarks.Text
                , ssMng.EmpSeqI);
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {

        }
    }
}